<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>生成一个新的签名公钥和挑战</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.openssl-spki-new" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">openssl_spki_new</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.6.0, PHP 7)</p><p class="refpurpose"><span class="refname">openssl_spki_new</span> &mdash; <span class="dc-title">生成一个新的签名公钥和挑战</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.openssl-spki-new-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>openssl_spki_new</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter reference">&$privkey</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter reference">&$challenge</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$algorithm</code><span class="initializer"> = 0</span></span>
  ] ) : <span class="type">string</span></div>

  <p class="para rdfs-comment">
   使用指定的哈希算法生成一个新的签名公钥和挑战。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.openssl-spki-new-parameters">
  <h3 class="title">参数</h3>
  <dl>

   
     <dt>
<code class="parameter">privkey</code></dt>

     <dd>

      <p class="para">
       <code class="parameter">privkey</code> 应该被设置为由<span class="function"><a href="openssl_pkey_new.html" class="function">openssl_pkey_new()</a></span>函数预先生成(或者以其他方式从openssl_pkey函数集中获得)的私钥。该密钥的相应公共部分将用于签署CSR.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">challenge</code></dt>

     <dd>

      <p class="para">
       与SPKAC有关的挑战。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">algorithm</code></dt>

     <dd>

      <p class="para">
       摘要算法。参见 openssl_get_md_method()函数。
      </p>
     </dd>

    
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.openssl-spki-new-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功，返回一个签名的公钥和挑战，失败返回 NULL .
  </p>
 </div>


  <div class="refsect1 errors" id="refsect1-function.openssl-spki-new-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   如果 <code class="parameter">algorithm</code> 参数是一个未知的签名算法，将会抛出一个 <strong><code>E_WARNING</code></strong> 级的错误。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.openssl-spki-new-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-951">
   <p><strong>Example #1 <span class="function"><strong>openssl_spki_new()</strong></span> 范例：</strong></p>
   <div class="example-contents"><p>
     使用默认的摘要算法(MD5)生成一个新的SPKAC
   </p></div>
   <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$pkey&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">openssl_pkey_new</span><span style="color: #007700">(</span><span style="color: #DD0000">'secret&nbsp;password'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$spkac&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">openssl_spki_new</span><span style="color: #007700">(</span><span style="color: #0000BB">$pkey</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'testing'</span><span style="color: #007700">);<br /><br />if&nbsp;(</span><span style="color: #0000BB">$spkac&nbsp;</span><span style="color: #007700">!==&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$spkac</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"SPKAC&nbsp;generation&nbsp;failed"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
MIICRzCCAS8wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDM3V3sS4o4
mB9dczziRnjGAmSp+JwPrHoYMAFGvDNmZGyiWfU586X4BKs++BAj7e/FsAfno0Hd
hN9FwpCNFSox30L03nQvLYJE7f/WqigwBeMRT7Op/xvFks4sT70xP2HRYv4KqP9a
WRcKU6cFH8VxhFhqM2txEIxZKdFLaL28yT7bEDmcglf4JLDdgNMb9rET1dkgtKE6
dOaJHPGjf1uvnOH4YwkQr7n4sLUR3Kdbh0ZJAFuQVDZulo+LLzxBBkqJJcB6FhF+
oXCdHTKZnqAhpWDz+NXYytAmevab6IYm5TWPWsJUv1YKJA5lg2mXbbloIZlN9Mgc
i9fi03bdw+crAgMBAAEWB3Rlc3RpbmcwDQYJKoZIhvcNAQEEBQADggEBALyUvP/o
pPSoWBlorFyZ2RnGwKf9qMpE0q2IJP7G3oDR4LyK/m933DUiZ+YnqThrH/CWb4Ek
y5I3OCyl3S4wCuU1ibZZwDVwYShr5ELp0J9PEf7qMQZOhNsizoC7k+Czb2xB6hYW
sKfsfTKm3cXBtH3fdgc/Z1Z7VSWnAzYo38snqm72NTf5yFRnrQdphNNXi+kn1zHA
lxXRyFDXHOcYsOnwAWfyXFA4QDHQ0ezz0UoCY8gJXovcZb4GRYqOLUAsF2HcNboy
29WN8VqE29sL9QxVZFlwMcqyoLcNnyw38GvNvAGqSvzzbnEFP2MAQXJVe0H0hdp/
MML5G2iNVgNozAo=
</pre></div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.openssl-spki-new-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><strong>openssl_spki_new()</strong></span></li>
    <li class="member"><span class="function"><a href="openssl_spki_export_challenge.html" class="function" rel="rdfs-seeAlso">openssl_spki_export_challenge()</a> - 导出与签名公钥和挑战相关的挑战字符串</span></li>
    <li class="member"><span class="function"><a href="openssl_spki_export.html" class="function" rel="rdfs-seeAlso">openssl_spki_export()</a> - 通过签名公钥和挑战导出一个可用的PEM格式的公钥</span></li>
    <li class="member"><span class="function"><a href="openssl_csr_new.html" class="function" rel="rdfs-seeAlso">openssl_csr_new()</a> - 生成一个 CSR</span></li>
    <li class="member"><span class="function"><a href="openssl_csr_sign.html" class="function" rel="rdfs-seeAlso">openssl_csr_sign()</a> - 用另一个证书签署 CSR (或者本身) 并且生成一个证书</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>